package com.sc.nft.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.dao.MallCategoryDao;
import com.sc.nft.entity.MallCategory;
import com.sc.nft.entity.vo.MallCategoryVO;
import com.sc.nft.exception.GlobalRunTimeException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.service.MallCategoryService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * IP商城分类表服务接口实现
 *
 * @author zxy
 * @description IP商城
 * @since 2023-05-10 16:59:01
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class MallCategoryServiceImpl implements MallCategoryService {
    private final MallCategoryDao mallCategoryDao;

    @Override
    public IPage<MallCategoryVO> categoryPage(String name, Boolean isVirtual, Page page) {
        return mallCategoryDao.categoryPage(page, name,isVirtual);
    }

    @Override
    public void addCategory(String name, Boolean isBrandUse, Integer sort, Integer isSearchCondition, Boolean isVirtual) {
        Assert.isNull(mallCategoryDao.getByName(name), () -> new GlobalRunTimeException("分类名称已存在"));

        MallCategory mallCategory = new MallCategory();
        mallCategory.setName(name);
        mallCategory.setIsBrandUse(isBrandUse);
        mallCategory.setSort(sort);
        mallCategory.setSearchCondition(isSearchCondition);
        mallCategory.setIsVirtual(isVirtual);
        mallCategory.insert();
    }

    /**
     * 获取分类列表
     *
     * @param isVirtual 是否为虚拟商品分类
     * @return
     */
    @Override
    public List<MallCategory> newCategoryList(Boolean isVirtual) {
        return mallCategoryDao.newCategoryList(isVirtual);
    }
}